home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / RGASM.RAR / ASMCODE.EXE / CHAPT7 / SCAN16.ASM < prev    next >
Encoding:
Assembly Source File  |  1993-05-10  |  4.3 KB  |  108 lines

  1. ;
  2. ;       Program Scan16 ( Chapter 7 )
  3. ;
  4.     page    55,132
  5. .model  small
  6. .stack
  7. .data
  8. CR      equ     00Dh            ; Carriage return code
  9. LF      equ     00Ah            ; Line feed code
  10. EscScan equ     001h            ; Scan code for ESC key
  11. EndMsg  equ     024h            ; Dollar sign - enf of message for DOS service
  12. BegMsg  db      CR,LF,LF
  13.     db      '   SCAN CODES BROWSER 1.3 ' , CR , LF , EndMsg
  14. Kbd83   db      CR,LF,'You have a standard 83-key keyboard',CR,LF,EndMsg
  15. Kbd101  db      CR,LF,'You have an enhanced 101/102 keyboard',CR,LF,EndMsg
  16. InsMsg  db      CR,LF,'Press ESC to exit else',CR,LF
  17.     db      'Press and relese any other key',CR,LF,LF,EndMsg
  18. FuncN   db      0
  19. LinePos db      0
  20. Con16   db      16
  21. OutByte db      'xx ',EndMsg
  22. CrLf    db      CR,LF,EndMsg
  23. SymCod  db      0
  24. HexTab  db      '0','1','2','3','4','5','6','7'
  25.     db      '8','9','A','B','C','D','E','F'
  26.  
  27. .code
  28.  
  29. PrtByte proc near
  30.     push    bx
  31.     push    dx
  32.     mov     ah,0                    ; AX now in range 0 - 255
  33.     div     Con16                   ; AL - first hex digit, AH - second
  34.     mov     bh,0                    ; Clear high part of BX
  35.     mov     bl,al                   ; Take the first hex digit
  36.     mov     al,HexTab[bx]           ; Take the corresponding character
  37.     mov     OutByte[0],al           ; Place it into output string
  38.     mov     bl,ah                   ; Take the second hex digit
  39.     mov     al,HexTab[bx]           ; Take the corresponding character
  40.     mov     OutByte[1],al           ; Place it into output string
  41.     lea     dx,OutByte              ; Addres of scan code text into DX
  42.     mov     ah,09                   ; Function 09h - output text string
  43.     int     21h                     ; Dos service call
  44.     pop     dx
  45.     pop     bx
  46.     ret
  47. PrtByte endp
  48.  
  49. Begin:
  50.  
  51.     mov     ax,@data
  52.     mov     ds,ax
  53.     lea     dx,BegMsg               ; Addres of start message into DX
  54.     mov     ah,09                   ; Function 09h - output text string
  55.     int     21h                     ; Dos service call
  56.  
  57.     mov     ax,40h                  ; 40h - segment address for BIOS area
  58.     mov     es,ax                   ; Place this address into ES
  59.     mov     bh,es:[62h]             ; BH - Video page number
  60.     test    byte ptr es:[96h],10h   ; Bit 4 - 101-key keyboard indicator
  61.     jnz     Pres101                 ; If enhanced keyboard is present
  62.     lea     dx,Kbd83                ; Addres of message into DX
  63.     mov     ah,09                   ; Function 09h - output text string
  64.     int     21h                     ; Dos service call
  65.     jmp     PrtInstr
  66.  
  67. Pres101:
  68.     mov     FuncN,10h               ; Enhanced input will be used
  69.     lea     dx,Kbd101               ; Addres of start message into DX
  70.     mov     ah,09                   ; Function 09h - output text string
  71.     int     21h                     ; Dos service call
  72.  
  73. PrtInstr:
  74.     lea     dx,InsMsg               ; Addres of message into DX
  75.     mov     ah,09                   ; Function 09h - output text string
  76.     int     21h                     ; Dos service call
  77.  
  78. NextKey:
  79.     mov     ah,FuncN                ; Function 0h or 10h - read character
  80.     int     16h                     ; BIOS keyboard service
  81.     cmp     ah,EscScan              ; Is the ESC key pressed?
  82.     je      Finis                   ; If it is so, finish the program
  83. ;       push    ax
  84.     mov     SymCod,al               ; Store the ASCII code
  85.     mov     al,ah                   ; Place the SCAN code into AL
  86.     call    PrtByte                 ; Output the SCAN code
  87. ;       pop     ax
  88.     mov     al,SymCod               ; Place the ASCII code into AL
  89.     call    PrtByte                 ; Output the ASCII code
  90.     mov     ah,0Ah                  ; Function 0Ah - Output character
  91.     mov     al,SymCod               ; AL - character to be output
  92.     mov     cx,1                    ; CX - counter of repeating output
  93.     int     10h                     ; BIOS video service call
  94.     mov     ah,09h                  ; Function 09h - Output text string
  95.     lea     dx,CRLF                 ; DS:DX - addres of string to be output
  96.     int     21h                     ; DOS service call
  97.     jmp     NextKey                 ; Read next key
  98.  
  99. Finis:
  100.  
  101.     mov     ah,0Ch                  ; Function 0Ch - clear keyboard buffer
  102.     int     21h                     ; Dos service call
  103.  
  104.     mov     ax,4C00h                ; Function 4Ch - terminate process
  105.     int     21h                     ; DOS service call
  106.  
  107.     end     Begin
  108.